package com.work.controller;


import com.alibaba.fastjson.JSON;
import com.work.pojo.GoodsType;
import com.work.pojo.User;
import com.work.service.GoodsTypeService;
import com.work.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 管理控制器
 *
 * @author gy
 * &#064;date 2022/09/29
 * @version 1.0.0
 * @since 1.0.0
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
	@Autowired
	private UserService userService;

	@Autowired
	private GoodsTypeService goodsTypeService;
	
	@PostMapping("/adminLogin")
	public ModelAndView adminLogin(String username, String password, HttpSession session, ModelAndView mv) {
		
		User admin = userService.adminLogin(username, password);
		if (admin != null) {
			session.setAttribute("admin", admin);
			mv.setViewName("redirect:/admin/admin.jsp");
			return mv;
		}
		mv.setViewName("redirect:/admin/login.jsp");
		return mv;
		
	}
	@RequestMapping("/logOut")
	public ModelAndView logOut(HttpSession session, ModelAndView mv) {
		session.invalidate();
		mv.setViewName("redirect:/admin/login.jsp");
		return mv;
	}

}
